package org.vestbjergbyggecenter.TUI;
import java.util.*;

import org.vestbjergbyggecenter.Controller.CustomerCtr;

public class CustomerMenuUI {
	
	    private CustomerCtr customerCtr;
	    private static CustomerMenuUI instance = null;
	    
	    private CustomerMenuUI()
	    {
	        customerCtr = CustomerCtr.getInstance();
	        start();
	    }
	    
	    public static CustomerMenuUI getInstance()
        {   
            instance = new CustomerMenuUI();
          
            return instance;
        }
	    
	    // start menu
	    public void start()
	    {
	        boolean exit = false;
	        while(!exit)
	        {
	            int choice = printCustomerMenu();
	            switch (choice)
	            {
	                case 1: listAll();
	                        break;
	                case 2: registerCustomer();
	                        break;
	                case 3: printMontlyBill();
	                        break;
	                case 4: readCustomer();
            				break;
	                case 5: updateCustomer();
	                		break;
	                case 6: deleteCustomer();
	                		break;
	                case 7: goBack();
	                        break;
	            }
	        }
	    }	    

		public int printCustomerMenu()
	    {
	        Scanner keyboard = new Scanner(System.in);
	        //System.out.print('\f');
	        System.out.println("***Customer Menu***");
	        System.out.println("1. List all customers");
	        System.out.println("2. Register a new customer");
	        System.out.println("3. Print month bill for a customer");
	        System.out.println("4. Read customer");
	        System.out.println("5. Change customer");
	        System.out.println("6. Delete customer");
	        System.out.println("7. Go back");
	        System.out.println("Choice #: ");
	        
	        int choice = keyboard.nextInt();
	        return choice;
	    }	
		
	    public void listAll()
	    {
	        System.out.print('\f');
	        customerCtr.printCustomers();
	    }
	    
	    public void registerCustomer()
	    {
	        Scanner keyboard = new Scanner(System.in); 
	        System.out.print('\f');
	        System.out.println("Customer ID: ");
	        int id = Integer.parseInt(keyboard.nextLine());
	        System.out.println("Person Name: ");
	        String name = keyboard.nextLine();
	        System.out.println("Person CPR: ");
	        long cpr = Long.parseLong(keyboard.nextLine());
	        System.out.println("Person Address: ");
	        String address = keyboard.nextLine();
	        System.out.println("Person Postal Code: ");
	        long postalCode = Long.parseLong(keyboard.nextLine());
	        System.out.println("Person City: ");
	        String city = keyboard.nextLine();
	        System.out.println("Person phone: ");
	        String phone = keyboard.nextLine();
	        System.out.println("Customer category: ");
	        String category = keyboard.nextLine();
	        customerCtr.createCustomer(id, name, cpr, address, postalCode, city, phone, category);   
	    }	    
	    
	    public void printMontlyBill()
	    {
	        Scanner keyboard = new Scanner(System.in);
	        System.out.print('\f');
	        System.out.println("Type customer ID: ");
	        int id = Integer.parseInt(keyboard.nextLine());
	        
	        customerCtr.printMonthBill(id);	        
	    }
	    
	    public void readCustomer()
	    {
	    	Scanner keyboard = new Scanner(System.in); 
	        System.out.print('\f');
	        System.out.println("Customer ID: ");
	        int id = Integer.parseInt(keyboard.nextLine());
			 System.out.println("ID   |  Name    |   Phone    |    Address   | Postal Code |   City   |   CPR   |   Category   |");
	        customerCtr.printCustomer(id);
	    }
	    
	    public void updateCustomer()
	    {
	    	Scanner keyboard = new Scanner(System.in); 
	        System.out.print('\f');
	        System.out.println("Customer ID: ");
	        int id = Integer.parseInt(keyboard.nextLine());
	        System.out.println("Person Name: ");
	        String name = keyboard.nextLine();
	        System.out.println("Person CPR: ");
	        long cpr = Long.parseLong(keyboard.nextLine());
	        System.out.println("Person Address: ");
	        String address = keyboard.nextLine();
	        System.out.println("Person Postal Code: ");
	        long postalCode = Long.parseLong(keyboard.nextLine());
	        System.out.println("Person City: ");
	        String city = keyboard.nextLine();
	        System.out.println("Person phone: ");
	        String phone = keyboard.nextLine();
	        System.out.println("Customer category: ");
	        String category = keyboard.nextLine();
	        customerCtr.updateCustomer(id, name, cpr, address, postalCode, city, phone, category);  
	    }
	    
	    public void deleteCustomer()
	    {
	    	Scanner keyboard = new Scanner(System.in); 
	        System.out.print('\f');
	        System.out.println("Customer ID: ");
	        int id = Integer.parseInt(keyboard.nextLine());
	    	
	        customerCtr.deleteCustomer(id);
	    }
	    
	    // calls and returns to main menu
	    public void goBack()
	    {
	        MainMenu.getInstance().start();
	    }
	}


